<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="dj.pageModel.*" %>
<script type="text/javascript">
	function addZhebiao() {
		$('<div/>').dialog({
			href : '${pageContext.request.contextPath}/app/company/datareport/zhebiao_xishu.jsp',
			width : 800,
			height : 310,
			modal : true,
			title : '添加折标系数',
			buttons : [ {
				text : '添加',
				iconCls : 'icon-add',
				handler : function() {
					var d = $(this).closest('.window-body');
					$.ajax({
						type : "POST",
						url : "${pageContext.request.contextPath}/zbxsAction!addZhebiaoxishu.action",
						dataType : "json",
						beforeSend : function() {
							var isValid = $("#company-report-zhebiaoxishu").form('validate');
							if (isValid) {
								$.messager.progress({
									text : "提交数据，请等待..."
								});
							}
							return isValid;
						},
						data : $("#company-report-zhebiaoxishu").serialize(),
						error : function(info) {
							$.messager.progress('close');
							eval(info.responseText);
						},
						success : function(result) {
							$.messager.show({
								msg : result.msg,
								title : '提示'
							});
							$.messager.progress('close');
							$('#company-report-zhebiaoxishu-list').datagrid('reload');
							d.dialog('destroy');
						}
					});
				}
			} ],
			onClose : function() {
				$(this).dialog('destroy');
			}
		});
	}

	function editZhebiao(id) {
		$('<div/>').dialog({
			href : '${pageContext.request.contextPath}/app/company/datareport/zhebiao_xishu.jsp',
			width : 800,
			height : 310,
			modal : true,
			title : '修改折标系数',
			buttons : [ {
				text : '保存',
				iconCls : 'icon-save',
				handler : function() {
					var d = $(this).closest('.window-body');
					$.ajax({
						type : "POST",
						url : "${pageContext.request.contextPath}/zbxsAction!updateZhebiaoxishu.action",
						dataType : "json",
						beforeSend : function() {
							var isValid = $("#company-report-zhebiaoxishu").form('validate');
							if (isValid) {
								$.messager.progress({
									text : "提交数据，请等待..."
								});
							}
							return isValid;
						},
						data : $("#company-report-zhebiaoxishu").serialize() + "&id=" + id,
						error : function(info) {
							$.messager.progress('close');
							eval(info.responseText);
						},
						success : function(result) {
							$.messager.show({
								msg : result.msg,
								title : '提示'
							});
							$.messager.progress('close');
							$('#company-report-zhebiaoxishu-list').datagrid('reload');
							d.dialog('destroy');
						}
					});
				}
			} ],
			onLoad : function() {
				$("#name").attr("disabled", true);
				$('#company-report-zhebiaoxishu').form('load', '${pageContext.request.contextPath}/zbxsAction!getZhebiaoxishuByid.action?id=' + id);
			},
			onClose : function() {
				$(this).dialog('destroy');
			}
		});
	}

	function changeZhebiaoStatus(id, name, status) {
		var infoMsg = "";
		if('<%=PzhebiaoXishu.SATUS_CLOSE %>' == status) {
			infoMsg = "您确定要是用标题为 “" + name + "” 的折标系数吗？";
		} else {
			$.messager.alert('提示','非法的状态！');
			return;
		}
		$.messager.confirm('提示', infoMsg, function(r) {
			if (r) {
				$.ajax({
					type : "post",
					dataType : "json",
					url : "${pageContext.request.contextPath}/zbxsAction!updateZbxsStatus.action",
					data : "id=" + id,
					error : function(info) {
						$.messager.show({
							msg : '获取信息失败！',
							title : '提示'
						});
						eval(info.responseText);
					},
					success : function(result) {
						$.messager.show({
							msg : result.msg,
							title : '提示'
						});
						$.messager.progress('close');
						$('#company-report-zhebiaoxishu-list').datagrid('reload');
					}
				});
			}
		});
	}

	$(function() {
		$('#company-report-zhebiaoxishu-list').datagrid({
			url : "${pageContext.request.contextPath }/zbxsAction!getZhebiaoxishuList.action",
			onLoadError : function(retValue) {
				eval(retValue.responseText);
			},
			singleSelect : true,
			pagination : true,
			fitColumns : true,
			pageSize : 10,
			pageList : [ 5, 10, 15, 20 ],
			nowrap : true,
			border : false,
			idField : 'id',
			toolbar : [ {
				text : '添加折标系数',
				iconCls : 'icon-add',
				handler : function() {
					addZhebiao();
				}
			} ],
			columns : [ [ {
				field : 'biaoti',
				title : '标题',
				width : 150
			}, {
				field : 'createDate',
				title : '创建日期',
				width : 180
			}, {
				field : 'status',
				title : '状态',
				width : 50,
				formatter : function(value) {
					if (value == '<%=PzhebiaoXishu.STATUS_OPEN %>') {
						return '使用中';
					} else if(value == '<%=PzhebiaoXishu.SATUS_CLOSE %>') {
						return '关闭';
					}
				}
			}, {
				field : 'id',
				title : '操作',
				width : 80,
				align : 'center',
				formatter : function(value, rowData, rowIndex) {
					if('<%=PzhebiaoXishu.SATUS_CLOSE %>' == rowData.status) {
						return "<a href='javascript:void(0)' onclick='editZhebiao(\"" + value + "\")'><img src='${pageContext.request.contextPath }/images/pencil.png' border='0'></a>&nbsp;&nbsp;" + 
								"<a href='javascript:void(0)' onclick='changeZhebiaoStatus(\"" + value + "\", \"" + rowData.biaoti + "\", \"<%=PzhebiaoXishu.SATUS_CLOSE%>\")'><img src='${pageContext.request.contextPath }/css/icons/database_start.gif' border='0'></a>";
					} else {
						return "<a href='javascript:void(0)' onclick='editZhebiao(\"" + value + "\")'><img src='${pageContext.request.contextPath }/images/pencil.png' border='0'></a>";
					}
				}
			} ] ]
		});
	});
</script>
<table id="company-report-zhebiaoxishu-list"></table>